package d8_thread_pool;

//线程的创建方式二
//1、定义一个类,实现Runnable接口
public class MyRunnable implements Runnable {
    //2、写线程要实现的任务
    @Override
    public void run() {
        for (int i = 0; i < 3; i++) {
            //3、获取线程的名字,并且输出结果
            System.out.println(Thread.currentThread().getName() + "输出了" + i);
            System.out.println(Thread.currentThread().getName() + "线程进入休眠了");

            //营造线程很忙
            try {
                Thread.sleep(Integer.MAX_VALUE);//然线程执行一次循环之后,直接休眠
            } catch (InterruptedException e) {
                return;
//                e.printStackTrace();
            }

            //上面出的异常
            /**
             * java.lang.InterruptedException: sleep interrupted
             * 	at java.base/java.lang.Thread.sleep(Native Method)
             * 	at d8_thread_pool.MyRunnable.run(MyRunnable.java:16)
             * 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
             * 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
             * 	at java.base/java.lang.Thread.run(Thread.java:833)
             *
             * 	表示线程被终端了
             */
        }
    }
}
